jQuery(document).ready(function() {
	//$('#lastUpdateDate').html(today);
	$('#btnAnalyzeDesc').click(function(event) {
		find();
	});
});
var apiUrl = '/api/Products/GetTATOutput';

function find() {
	var input = $('#caseDesc').val();
	$("#icon-loading").show();

	$.getJSON(apiUrl + '/?input=' + input)
	.done(function (data) {
		var objXHR = eval("(" + data + ")");
		$('#progressBarsDiv').show();
	            //progressBar1
	            progress(objXHR.LTA, $('#progressBar1'));
	            //progressBar2
	            progress(objXHR.NEA, $('#progressBar2'));
	            //progressBar3
	            progress(objXHR.PUB, $('#progressBar3'));
	            //Recommended Agency
	            var recomAgency = objXHR.RecomAgency;
	            $("#recomAgency").html(recomAgency);
	            $('#autoComp-agency').val(recomAgency);
	            //$('#tatOutput').html(objXHR.LTA);
	          	//$("#probOutput").show();
	          	$("#icon-loading").hide();
	          	progress(80, $('#progressBar'));
	          	//$.jGrowl("Analysis completed!");
	          })
	.fail(function (jqXHR, textStatus, err) {
            //$('#tatOutput').val('Error: ' + err);
            $('#recomAgency').html('Error: ' + err);
            $("#icon-loading").hide();
            //$("#probOutput").show();
        });
}
function progress(percent, $element) {
	var progressBarWidth = percent * $element.width() / 100;
	$element.find('div').animate({ width: progressBarWidth }, 500).html(percent + "%&nbsp;");
}